#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"
using std::placeholders::_1;
class Listener:public rclcpp::Node
{
public:
    Listener():Node("listen_node_cpp")
    {
        RCLCPP_INFO(this->get_logger(),"订阅节点已创立");
        subscription_=this->create_subscription<std_msgs::msg::String>("chatter",10,std::bind(&Listener::topic_callback,this,_1));
    }
    private:
        void topic_callback(const std_msgs::msg::String &msg)const
        {
            RCLCPP_INFO(this->get_logger(),"订阅到的消息是：%s",msg.data.c_str());
        }
        std::shared_ptr<rclcpp::Subscription<std_msgs::msg::String>>subscription_;
};
int main(int argc,char*argv[])
{
    rclcpp::init(argc,argv);
    rclcpp::spin(std::make_shared<Listener>());
    rclcpp::shutdown();
    return 0;
}